<template>
	<view class="sub-pl">
		<view v-if="comments">
			<!-- 先渲染主评论 -->
			<view class="pinglunItem">
				<!-- 先渲染 不是 恢复 某个 评论 的回复 -->
				<view class="plBox">
					<view class="pinglunItem-left">
						<image :src="comments.user.avatarUrl" mode=""></image>
					</view>
					<view class="pinglunItem-right">
						<view class="one">
							<view class="name">
								<text>{{comments.user.nickname}}</text>
								<image src="/static/huiyuan.png" mode="" v-if="comments.user.vipType!==0"></image>
							</view>
							<view class="zan">
								{{comments.likedCount === 0 ? '': comments.likedCount}}
								<i class="iconfont icon-tuijian"></i>
							</view>
						</view>
						<view class="timer">
							{{comments.time | timer}}
						</view>
						<view class="text">
							<!-- 回复的评论 -->
							<view class="text-huifu">
								{{comments.content}}
							</view>
						</view>
					</view>
					<!-- 展示的 回复别人评论  的  评论 -->
					<!-- <showPl v-if="item.huifu.length !== 0"/> -->
				</view>
			</view>

			<!-- 上面 主评论 的 全部的评论 -->
			<view class="quanbuhuifu">
				全部回复
			</view>
			<scroll-view scroll-y="true" style="height: 600rpx;">
				<view class="pinglunItem quanbuhuifu-comments" v-for="(item,index) in comments.huifu" :key="index">
					<!-- 先渲染 不是 恢复 某个 评论 的回复 -->
					<view class="plBox">
						<view class="pinglunItem-left">
							<image :src="item.user.avatarUrl" mode=""></image>
						</view>
						<view class="pinglunItem-right">
							<view class="one">
								<view class="name">
									<text>{{item.user.nickname}}</text>
									<image src="/static/huiyuan.png" mode="" v-if="item.user.vipType!==0"></image>
								</view>
								<view class="zan">
									{{item.likedCount === 0 ? '': item.likedCount}}
									<i class="iconfont icon-tuijian"></i>
								</view>
							</view>
							<view class="timer">
								{{item.time | timer}}
							</view>
							<view class="text">
								<!-- 回复的评论 -->
								<view class="text-huifu">
									{{item.content}}
								</view>
							</view>
						</view>
						<!-- 展示的 回复别人评论  的  评论 -->
						<!-- <showPl v-if="item.huifu.length !== 0"/> -->
					</view>
				</view>

			</scroll-view>
			<!-- 回复评论 -->
			<view class="huifu-pl">
				<!-- 输入框头部图标 -->
				<view class="search">
					<uni-easyinput prefixIcon="search" suffixIcon="closeempty" v-model="value" placeholder="请输入内容"
						@iconClick="onClick"></uni-easyinput>
				</view>
				<view class="fasong">
					发送
				</view>
			</view>
		</view>
	</view>
</template>
<script>
	import moment from 'moment'
	export default {
		data() {
			return {
				value: '写评论~~~', // 输入框的值
			}
		},
		props: {
			comments: {
				type: Object,
				default: () => {}
			}
		},
		methods: {
			onClick() {
				this.value = ''
			}
		},
		// 为了 处理 多个平台的样式穿透
		options: {
			styleIsolation: 'shared'
		},
		onLoad() {
			console.log(this.comments);
		},
		filters: {
			timer: function(timer) {
				// 这个日期是 数据库传过来的
				let Time = moment(timer).format('YYYY-MM-DD')
				// 这个是今天的日期
				let NowTime = moment().format('YYYY-MM-DD')
				let day = (NowTime.substr(8, 2)) - (Time.substr(8, 2))
				if (Time === NowTime) {
					return moment(timer).format('hh : mm')
				} else if ((Time.substr(0, 4)) === (NowTime.substr(0, 4))) {
					// console.log('走了');
					// 年份一致
					if ((Time.substr(5, 2)) === (NowTime.substr(5, 2))) {
						// 月份一致
						if (day == 1) {
							// 差一天
							return '昨天' + moment(timer).format('hh : mm')
						} else {
							return moment(timer).format('YYYY年MM月DD日')
						}

					} else {
						return moment(timer).format('YYYY年MM月DD日')
					}
				} else {

					return moment(timer).format('YYYY年MM月DD日')
				}

			}
		}
	}
</script>
<style lang="less">
	.sub-pl {
		margin-top: 40rpx;

		// 回复评论 的固定定位
		.huifu-pl {
			position: fixed;
			display: flex;
			left: 0;
			bottom: 0;
			height: 72rpx;
			// background-color: red;
			width: 100%;

			.fasong {
				// background-color: #C0C0C0;
				text-align: center;
				color: #333333;
				width: 100rpx;
				height: 72rpx;
				line-height: 72rpx;
			}

			.search {
				width: calc(100% - 100rpx);
			}


		}

		.quanbuhuifu {
			padding-top: 20rpx;
			padding-bottom: 20rpx;
			font-weight: bold;
		}

		.quanbuhuifu-comments {
			// height: 660rpx;
			// background-color: red;
		}

		.pinglunItem {

			.plBox {
				display: flex;
				padding-bottom: 20rpx;

				.pinglunItem-left {
					margin-right: 20rpx;

					image {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
					}
				}

				.pinglunItem-right {
					width: 100%;
					border-bottom: 1px solid #ccc;
					padding-bottom: 10rpx;

					.one {
						display: flex;
						justify-content: space-between;
						height: 50rpx;

						.name {
							font-size: 36rpx;

							image {
								margin-left: 10rpx;
								width: 70rpx;
								height: 24rpx;

							}
						}

						.zan {
							display: flex;
							font-size: 26rpx;
							color: #C0C0C0;
						}
					}

					// 时间
					.timer {
						font-size: 24rpx;
						color: #999999;
					}

					.text {
						padding-top: 20rpx;
						padding-bottom: 20rpx;
					}


				}
			}

		}
	}
</style>
